import { netWork } from '@/network/request.js';

class Axios { // Axios请求构造类
  constructor () {
  }

  getRequst (url, params = null) { // GET请求函数
    return netWork({
      url,
      method: 'GET',
      params
    })
  }
  
  getPost (url, data = null) { // POST请求函数
    return netWork({
      url,
      method: 'POST',
      data
    })
  }

  getPut (url, params = null, data = null) { // POST请求函数
    // console.log(url, params);
    return netWork({
      url,
      method: 'PUT',
      params,
      data
    })
  }

  getDel (url) {
    return netWork({
      url,
      method: 'DELETE'
    })
  }

}



function getGoodOptionList () { // 获取所有商品数据列表
  return new Axios().getRequst('categories');
}

function getGoodOptionDataList (id, paramsObj) { // 获取商品参数列表[静态 or 动态]
  return new Axios().getRequst(`categories/${id}/attributes`, paramsObj);
}

function postAddGoodOption (id, bodyObj) { // post请求发送添加商品信息
  return new Axios().getPost(`categories/${id}/attributes`, bodyObj);
}

function getInfoById (id, attrId, paramsObj) {
  return new Axios().getRequst(`categories/${id}/attributes/${attrId}`, paramsObj);
}

function putEditGoodOption (id, attrId, putObj) {
  return new Axios().getPut(`categories/${id}/attributes/${attrId}`,null, putObj);
}

function delOptionById (id, attrId) {
  return new Axios().getDel(`categories/${id}/attributes/${attrId}`);
}

function putAddOption (id, attrId, bodyObj) { //为静态、动态参数添加val参数属性值 即 tag渲染的
  return new Axios().getPut(`categories/${id}/attributes/${attrId}`, null, bodyObj);
}

export {
  getGoodOptionList,
  getGoodOptionDataList,
  postAddGoodOption,
  getInfoById,
  putEditGoodOption,
  delOptionById,
  putAddOption
}


